package org.ajc.base.service.impl;

import org.ajc.base.mapper.BaseMapper;
import org.ajc.base.query.BaseQuery;
import org.ajc.base.service.IBaseService;
import org.ajc.base.util.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.io.Serializable;
import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Transactional
    @Override
    public void insert(T t) {
        baseMapper.insert(t);
    }

    @Transactional
    @Override
    public void delete(Serializable id) {
        baseMapper.delete(id);
    }

    @Transactional
    @Override
    public void batchDelete(List<Serializable> ids) {
        baseMapper.batchDelete(ids);
    }

    @Transactional
    @Override
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    public T selectById(Serializable id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<T> selectAll() {
        return baseMapper.selectAll();
    }

    @Override
    public PageInfo queryPage(BaseQuery baseQuery) {
        // 查询所有数据
        Long total = baseMapper.queryTotal(baseQuery);
        if (total != 0){
            // 查询分页数据
            List<T> list = baseMapper.queryPage(baseQuery);
            return new PageInfo<>(total,list);
        }
        return  new PageInfo<>();
    }
}
